﻿Imports System.IO.IsolatedStorage
Imports Microsoft.Xna.Framework.Audio
Imports Microsoft.Xna.Framework.Graphics
Imports Runa.Common.Helper
Imports Runa.Foundation.IO
Imports Runa.Resources.ResourceManager
Imports System.IO

Namespace Global.Runa.Resources.ContentManagers

    Public Class GameDirectoryContentManager
        Inherits BasicContentManager

        Public Property GameDirectoryRoot() As String
        Public Property PhysicalStorage() As GameDirectory

        Public Sub New(serviceProvider As System.IServiceProvider, Optional ByVal fs As GameDirectory = Nothing)
            MyBase.New(serviceProvider)
            Me.GameDirectoryRoot = ""
            Me.PhysicalStorage = If(fs, New IsolatedFileStorageGameDirectory())
        End Sub

        Public Sub New(serviceProvider As System.IServiceProvider, rootDirectory As String, Optional ByVal fs As GameDirectory = Nothing)
            MyBase.New(serviceProvider, rootDirectory)
            Me.GameDirectoryRoot = rootDirectory
            Me.PhysicalStorage = If(fs, New IsolatedFileStorageGameDirectory())
        End Sub

        Public Overrides Function Exists(ByVal assetName As String) As Boolean
            Return Me.PhysicalStorage.FileExists(Path.Combine(Me.GameDirectoryRoot, assetName))
        End Function

        Protected Overrides Function OpenStream(assetName As String) As System.IO.Stream
            Return Me.PhysicalStorage.OpenFile(Path.Combine(Me.GameDirectoryRoot, assetName), System.IO.FileMode.Open, FileAccess.Read)
        End Function

    End Class

End Namespace